import { loginAPI } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
const state = () => {
  return {
    token: getToken() || ''
  }
}
const mutations = {
  SET_TOKEN(state, token) {
    state.token = token
    // 将ztoken存储到cookie中
    setToken(token)
  },
  dleteToken(state) {
    state.token = ''
    removeToken()
  }
}
const actions = {
  async onLogin(ctx, data) {
    const res = await loginAPI(data)
    // console.log(res)
    ctx.commit('SET_TOKEN', res.data.token)
    // setToken(res.data.token)
    // console.log('token存储成功')
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
